(function(){

	var publicMethod = function(){} ;
	var blackId ;

	publicMethod.prototype = {
		//删除数组指定值
		removeValue:function(arr,value){
			if(arr.length > 0 ){
				var newarr = [] ;
				for(var i=0;i<arr.length;i++){
					if(arr[i] == value){

					}else{
						newarr[newarr.length] = arr[i] ;
					}
				}

				return newarr ;
			}

			return arr ;
		},

		//判断是否含有某class
		hasClass:function(obj,newName){
			if(!obj){
				return false ;
			}
			
			var oldName = obj.className ;
			if(oldName.length == 0){ 
				return false ;
			}
			
			if(oldName==newName || oldName.match(new RegExp("(^|\\s)" + newName + "(\\s|$)"))){
				return true ;
			}

			return false ;
		},

		//添加class
		addClass:function(obj,newName){
			if(!obj){
				return  ;
			}
			
			var oldName = obj.className ;
			if(oldName.length == 0){
				obj.className = newName ;
				return ;
			}
			
			if(oldName==newName || oldName.match(new RegExp("(^|\\s)" + newName + "(\\s|$)"))){
				return ;
			}
			obj.className = oldName + " " + newName; 
		},
		
		//删除class
		removeClass:function(obj,newName){
			if(!obj){
				return  ;
			}
			
			var oldName = obj.className ;
			if(oldName.length == 0){
				return ;
			}
			
			if(oldName==newName || oldName.match(new RegExp("(^|\\s)" + newName + "(\\s|$)"))){
				obj.className = oldName.replace((new RegExp("(^|\\s)" + newName + "(\\s|$)"))," ") ;
				return ;
			}
		},


		//存放cookie变量
		setCookie:function(name,value,minutes,path,domain,secure){
			sessionStorage.setItem(name,value) ;
			
			if(minutes == undefined){
				minutes = 30 ;
			}
			if(path == undefined){
				path = "/" ;
			}	
			value = encodeURIComponent(value);
	        var cdata = name + "=" + value;
	        if(minutes > 0){
	            var d = new Date();
	            d.setMinutes(d.getMinutes() + minutes) ;
	            cdata += "; expires=" + d.toGMTString();
	        }
	        cdata +=path ? ("; path=" + path) : "" ;
	        cdata +=domain ? ("; domain=" + domain) : "" ;
	        cdata +=secure ? ("; secure=" + secure) : "" ;

	        document.cookie = cdata;
	    },
     
     	//获取cookie变量
    	getCookie:function(name){
    		value = sessionStorage.getItem(name);
    		if(value && value!=""){
    			return value ;
    		}

	        var reg = eval("/(?:^|;\\s*)" + name + "=([^=]+)(?:;|$)/"); 
	        var value = reg.test(document.cookie) ? RegExp.$1 : "";
	        value = decodeURIComponent(value);        
	        if(!value){
	        	value = "";
	        }

	        return value;
	    },

	    //将json字符串转换成json对象
	    parse:function(data){
	    	if(data == ""){
				return (new Function("return null"))();
			}else{
				return (new Function("return (" + data + ")"))();
			}
	    },
	    //替换所有
		replaceAll:function(str,code,newcode){
			while(str.indexOf(code) >= 0){
				str = str.replace(code,newcode) ;
			}
			return str ;
		},


		//获取网址后面参数
		getUrlParam:function (m){
			var value = "";
			var _href = window.location.href.split("?");
			var a = window.location.href ;
			var d = escape(a) ;
	        if(_href.length>1){
	        	if(_href[1].indexOf("&")>0){
	        		var arr = _href[1].split("&");
	        		for (var i = 0; i < arr.length; i++) {
	        			var p = arr[i].split("=")[0];
	        			if(m==p){
	        				value= arr[i].split("=")[1];
	        			}
	        		}
	        	}else{
	        		var p = _href[1].split("=")[0];
	        		if(m==p){
	        			value= _href[1].split("=")[1];
	        		}
	        	}
	        }
			return value;
		},


		//判断设备是Android还是iPhone
		androidOrIphone:function(){
			var system = window.navigator.userAgent.toLowerCase() ;
		    if(system.indexOf("iphone")>=0 || system.indexOf("ipad")>=0 || system.indexOf("mac")>=0){
		    	return false ;
		    }
			
			return true ;
		},

		//删除cookie变量
		removeCookie:function(name){
			sessionStorage.removeItem(name) ;
    	
	    	this.setCookie(name,"",-1,"/") ;
	    	var date=new Date();
	        date.setTime(date.getTime()+30*60*1000);
	        document.cookie=name+"=; expire="+date.toGMTString()+"; path=/";
		},

		//判断是否登录
		isLogin:function(){
			if(this.getCookie("userInfo")){
				return true ;
			}

			return false ;
		},

		//黑框提示
		blackTs:function(str){
			if(document.getElementById("blackDiv")){
				document.getElementById("blackSpan").innerHTML = str ;
			}else{
				var blackDiv = document.createElement("div") ;

				blackDiv.id = "blackDiv" ;
				blackDiv.className = "blackts" ;
				blackDiv.style.position = "fixed" ;
				blackDiv.style.bottom = "2.4rem" ;
				blackDiv.style.width = "100%" ;
				blackDiv.style.textAlign = "center" ;
				blackDiv.style.zIndex = "999999" ;

				var html = '<span id="blackSpan" style="background: rgba(0,0,0,.86);color: white;' ;
				html += 'border-radius: .1rem;font-size: 0.3rem;padding: .2rem .6rem;">' ;
				html += str+'</span>' ;
				blackDiv.innerHTML = html ;

				document.getElementsByTagName("body")[0].appendChild(blackDiv);
			}

			if(blackId && blackId!=""){
				clearTimeout(blackId) ;
			}
			blackId = setTimeout(function(){
				if(document.getElementById("blackDiv")){
					document.getElementsByTagName("body")[0].removeChild(document.getElementById("blackDiv"));
				}
			},2000) ;
		},
		//设置客户端头部标题
		getSome:function (param){
			var getparam = this.getUrlParam(param);
			if(getparam != ""){
				this.setCookie(param,getparam,60*24*30) ;
			}else{
				getparam = this.getCookie(param) ; 
			}
			return getparam ;
		},
		sendToClient:function(param){
			if(window.webCallLocal){//android
				webCallLocal.setData(JSON.stringify(param));
			}
			if(!this.androidOrIphone() && this.getSome("version") >= "4.1.0"){//ios
				this.sendToClientIOS(param);
			}
		},
		sendToClientIOS:function(param){
			var iFrame,url;
			url = 'qmcaijs://autoweb?param='+encodeURI(JSON.stringify(param));
            iFrame = document.createElement("iframe");
            iFrame.setAttribute("src", url);
            iFrame.setAttribute("style", "display:none;");
            iFrame.setAttribute("height", "0px");
            iFrame.setAttribute("width", "0px");
            iFrame.setAttribute("frameBorder", "0");
            document.body.appendChild(iFrame);
            // 发起请求后这个 iFrame 就没用了，所以把它从 dom 上移除掉
            iFrame.parentNode.removeChild(iFrame);
            iFrame = null;
		},

		//判断对象是否为空
		objIsEmpty:function(obj){
			for(var name in obj){
				return true ;
			}

			return false ;
		}
	};

	
	//安卓使用backH5Control=true，让h5控制客户端活动返回
    function clientBack(){
        headBack() ;
    }
    window.clientBack = clientBack ;

    function $(id){
		return document.getElementById(id) ;
	}
	
	window.publicMethod = publicMethod ;
})() ;